@extends('admin.common.base-master')

@section('html-head')

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.couponsList')}}">查看用户余额</a>
        </div>
        @include('admin.common.distribution-header')
        <div class="filter-box clearfix">

            <div class="fr">
{{--                <a class="addBtn" href="{{route("Admin.Home.couponsSet")}}">新增</a>--}}
                <a class="addBtn" style="cursor: pointer" onclick="upPop(0,'')">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户昵称</th>
                    <th>用户头像</th>
                    <th>手机号</th>
                    <th>余额</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($data) > 0)
                    @foreach($data as $item)
                        <tr id="leader_{{$item->id}}">
                            <td>{{$item->id}}</td>
                            <td>{{$item->nickname}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if(isset($item->img_url ) && $item->img_url !='')
                                        <img src="{{$item->img_url}}" alt="用户头像">
                                    @endif
                                </span>
                            </td>
                            <td>{{$item->phone}}</td>
                            <td>{{$item->first_level_number}}</td>
                            <td>{{$item->amount}}</td>
                            <td>{{$item->created_at}}</td>
                            <td>
                                <a class="color2" style="cursor: pointer" onclick="upPopMoney({{$item->user_id}})">提现</a>
                                <a class="color2" style="cursor: pointer" onclick="upPop({{$item->id}},{{$item->phone}})">编辑</a>
                                <a href="javascript:void(0);" class="del" data-id="{{$item->id}}" >删除</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $data->render(); ?>
        </div>
        <div class="upPop-box">
            <div class="backdrop"></div>
            <div id="upPop" class="info-pop tixian" style="position: relative;">
                <input type="hidden" name="id" id="classifyid" value=""/>
                <a class="close" href="javascript:void(0);"></a>
                <h3>新增/编辑团长信息</h3>

                <div class="fill-list" style="height: 200px;overflow: auto;">
                    <div>请输入团长手机号
                        <input type="hidden" name="id" id="id" value="0">
                        <input type="text" name="phone" id="input_phone" value="">
                    </div>
                </div>
                <div class="fill-list" style="position: absolute;bottom: 5px">
                    <span class="fill-tit">&nbsp;</span>
                    <input class="fill-submit" type="button" id="subThisForm" value="提交">
                </div>
            </div>
        </div>

        <div class="upPop-box-money">
            <div class="backdrop"></div>
            <div id="upPop" class="info-pop tixian" style="position: relative;">
                <input type="hidden" name="id" id="classifyid" value=""/>
                <a class="close-money" href="javascript:void(0);"></a>
                <h3>新增提现记录</h3>

                <div class="fill-list" style="height: 200px;overflow: auto;">
                    <div>请输入提现金额（单位：元）
                        <input type="hidden" name="user_id" id="user_id" value="0">
                        <input type="text" name="amount" id="input_amount">
                    </div>
                </div>
                <div class="fill-list" style="position: absolute;bottom: 5px">
                    <span class="fill-tit">&nbsp;</span>
                    <input class="fill-submit" type="button" id="subThisFormMoney" value="提交">
                </div>
            </div>
        </div>
    </div>
    <script>

        function upPop(id,phone){
            $('.upPop-box').upPop();
            $("#id").val(id);
            $("#input_phone").val(phone);
        }

        $(document).on('click', '#subThisForm', function () {
            var id = $('#id').val();
            var phone  = $('#input_phone').val();

            $.ajax({
                url: '{{route("Distribution.Admin.addDistributionLeader")}}',
                type: 'post',
                dataType: 'json',
                data: {
                    id: id,
                    phone : phone
                },
                success: function (obj) {
                    if (obj.level == "success") {
                        noty({
                            text: obj.message, type: obj.level, timeout: 600,
                            callback: {
                                afterClose:function(){
                                    window.location.reload();
                                }
                            }
                        });
                    } else if (obj.level == "error") {
                        noty({text: obj.message, type: obj.level, timeout: 600});
                    }

                },
                error: function (obj) {
                    console.log(obj);
                }
            });
        });

        $(document).on("click",".del",function(){
            var id = $(this).attr("data-id");
            noty({
                text: '你确定要删除吗?',
                buttons: [
                    {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Distribution.Admin.delDistributionLeader')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#leader_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                    },
                    {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                    }
                ]
            });

        });

        function upPopMoney(user_id){
            $('.upPop-box-money').upPop();
            $("#user_id").val(user_id);
        }
        $(document).on('click', '#subThisFormMoney', function () {
            var user_id = $('#user_id').val();
            var amount  = $('#input_amount').val();

            $.ajax({
                url: '{{route("Distribution.Admin.exchangeRebate")}}',
                type: 'post',
                dataType: 'json',
                data: {
                    user_id: user_id,
                    amount : amount
                },
                success: function (obj) {
                    if (obj.level == "success") {
                        noty({
                            text: obj.message, type: obj.level, timeout: 600,
                            callback: {
                                afterClose:function(){
                                    window.location.reload();
                                }
                            }
                        });
                    } else if (obj.level == "error") {
                        noty({text: obj.message, type: obj.level, timeout: 600});
                    }

                },
                error: function (obj) {
                    console.log(obj);
                }
            });
        });
    </script>
@endsection